﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Resources;
using System.Reflection;

namespace LaMalleAJeux.Helpers
{
    public static class HtmlHelperExtension
    {
        public static ResourceManager resourceManager = new ResourceManager("LaMalleAJeux.Properties.Resources", Assembly.GetExecutingAssembly());

        public static string Localise(this HtmlHelper helper, string text)
        {
            string translation = resourceManager.GetString(text);

            if(string.IsNullOrEmpty(translation ))
            {
                throw new MissingFieldException(text + " has not been translated!");
            }

            return translation;
        }

        public static string Localise(this HtmlHelper helper, string text, List<string> arguments)
        {
            string translation = resourceManager.GetString(text);

            if (string.IsNullOrEmpty(translation))
            {
                throw new MissingFieldException(text + " has not been translated!");
            }

            return string.Format(translation, arguments.ToArray<string>());
        }
    }
}